import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    role: ['admin','editor']     will control the page role (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if fasle ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  { path: '/login', component: _import('login/index'), hidden: true },
  { path: '/authredirect', component: _import('login/authredirect'), hidden: true },
  { path: '/404', component: _import('errorPage/404'), hidden: true },
  { path: '/401', component: _import('errorPage/401'), hidden: true },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [{
      path: 'dashboard',
      component: _import('dashboard/index'),
      name: 'dashboard',
      meta: { title: 'dashboard', icon: 'dashboard', noCache: true }
    }]
  }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/monitor',
    component: Layout,
    redirect: 'monitor',
    name: 'Monitor',
    meta: { title: 'monitor', icon: 'monitor' },
    children: [
      {
        path: 'device',
        name: 'Device',
        component: _import('monitor/device/index'),
        meta: { title: 'device', icon: 'device' }
      },
      {
        path: 'distribution',
        name: 'Distribution',
        component: _import('monitor/distribution/index'),
        meta: { title: 'distribution', icon: 'distribution' }
      },
      {
        path: 'filter',
        name: 'Filter',
        component: _import('monitor/filter/index'),
        meta: { title: 'filter', icon: 'filter' }
      },
      {
        path: 'behavior',
        name: 'Behavior',
        component: _import('monitor/behavior/index'),
        meta: { title: 'behavior', icon: 'behavior' }
      },
      {
        path: 'weekly',
        name: 'Weekly',
        hidden: false,
        component: _import('monitor/weekly/index'),
        meta: { title: 'weekly', icon: 'weekly' }
      },
      {
        path: 'twoDay',
        name: 'TwoDay',
        component: _import('monitor/twoDay/index'),
        meta: { title: 'twoDay', icon: 'twoDay' }
      },
      {
        path: 'sevenDay',
        name: 'SevenDay',
        component: _import('monitor/sevenDay/index'),
        meta: { title: 'sevenDay', icon: 'sevenDay' }
      },
      {
        path: 'appOpenSort',
        name: 'AppOpenSort',
        component: _import('monitor/appOpenSort/index'),
        meta: { title: 'appOpenSort', icon: 'appOpenSort' }
      },
      {
        path: 'appMotionSort',
        name: 'AppMotionSort',
        component: _import('monitor/appMotionSort/index'),
        meta: { title: 'appMotionSort', icon: 'appMotionSort' }
      },
      {
        path: 'deviceMotionSort',
        name: 'DeviceMotionSort',
        component: _import('monitor/deviceMotionSort/index'),
        meta: { title: 'deviceMotionSort', icon: 'deviceMotionSort' }
      }
    ]
  },
  {
    path: '/application',
    component: Layout,
    redirect: '/application/table',
    name: 'Application',
    meta: { title: 'application', icon: 'application' },
    children: [
      {
        path: 'app',
        name: 'App',
        component: _import('application/app/index'),
        meta: { title: 'app', icon: 'app' }
      },
      {
        path: 'versionInfo',
        name: 'VersionInfo',
        component: _import('application/app/versionIndex'),
        meta: { title: 'versionInfo', icon: 'versionInfo' }
      },
      {
        path: 'tag',
        name: 'Tag',
        component: _import('application/tag/index'),
        meta: { title: 'tag', icon: 'tag' }
      },
      {
        path: 'vendor',
        name: 'Vendor',
        component: _import('application/vendor/index'),
        meta: { title: 'vendor', icon: 'vendor' }
      },
      {
        path: 'hotSearch',
        name: 'HotSearch',
        component: _import('application/hot/index'),
        meta: { title: 'hotSearch', icon: 'hotSearch' }
      }
    ]
  },
  {
    path: '/recommend',
    component: Layout,
    redirect: '/recommend/table',
    name: 'Recommend',
    meta: { title: 'recommend', icon: 'recommend' },
    children: [
      {
        path: 'section',
        name: 'Section',
        component: _import('recommend/section/index'),
        meta: { title: 'section', icon: 'section' }
      },
      {
        path: 'listGroup',
        name: 'ListGroup',
        component: _import('recommend/listGroup/index'),
        meta: { title: 'listGroup', icon: 'listGroup' }
      },
      {
        path: 'storeList',
        name: 'StoreList',
        component: _import('recommend/storeList/index'),
        meta: { title: 'storeList', icon: 'storeList' }
      }
    ]
  },
  {
    path: '/lockScreen',
    component: Layout,
    redirect: '/lockScreen/table',
    name: 'LockScreen',
    meta: { title: 'lockScreen', icon: 'lockScreen' },
    children: [
      {
        path: 'screen',
        name: 'Screen',
        component: _import('lockScreen/screen/index'),
        meta: { title: 'screen', icon: 'section' }
      },
      {
        path: 'screenGroup',
        name: 'ScreenGroup',
        component: _import('lockScreen/screenGroup/index'),
        meta: { title: 'screenGroup', icon: 'listGroup' }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/table',
    name: 'User',
    hidden: true,
    meta: { title: 'user', icon: 'user' },
    children: [
      {
        path: 'info',
        name: 'info',
        component: _import('user/info/index'),
        meta: { title: 'info', icon: 'info' }
      },
      {
        path: 'pw',
        name: 'pw',
        component: _import('user/pw/index'),
        meta: { title: 'pw', icon: 'password' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]
